package com.jesper.seckill.controller;

import com.jesper.seckill.constant.MqConstant;
import com.jesper.seckill.service.mq.MQMessageConsumeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class MQMessageConsumeController {

    @Autowired
    private MQMessageConsumeService mQMessageConsumeService;

    /**
     * 用户商品秒杀成功 - 消费者消息队列信息
     * @param message
     */
    @RabbitListener(queues = {MqConstant.SECKILL_GOODS_ORDER_QUEUE},containerFactory = "rabbitListenerContainerFactory")
    @RabbitHandler
    public void consumeSeckillMessage(String message){
        log.info("从消息队列[" + MqConstant.SECKILL_GOODS_ORDER_QUEUE + "]接收到消息：" + message);
        mQMessageConsumeService.consumeSeckillMessage(message);
    }
}
